import { GetRoutes } from '@/router/index.jsx';
import { RouteGuard } from '@/components/index.jsx';
import { ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { geIsLogin } from '@/selector/user.js';
import { UserAction } from '@/actions/user/action.js';

function App() {
  const isLogin = useSelector(geIsLogin);
  const dispatch = useDispatch();

  useEffect(() => {
    // 用户已经登录 获取用户登录信息
    if (isLogin) {
      dispatch(UserAction.getLoginUser());
    }
  }, [isLogin]);

  return (
    <ConfigProvider locale={zhCN}>
      <RouteGuard>
        <GetRoutes />
      </RouteGuard>
    </ConfigProvider>
  );
}

export default App;
